package com.example.spinning.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.spinning.bean.PaginationResult;
import com.example.spinning.bean.QualityReport;
import com.example.spinning.mapper.QualityReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;


@Service
@Transactional
public class QualityReportService {
    @Autowired
    QualityReportMapper qualityReportMapper;




    //增加操作
    public int addNewQualityReport(QualityReport qualityReport) {
        return qualityReportMapper.addNewQualityReport(qualityReport);
    }

    //删除操作
    public boolean deleteQualityReportById(Long[] ids) {
        int result = qualityReportMapper.deleteQualityReportById(ids);
        return result == ids.length;
    }
    //查询并分页
//    public PageInfo<QualityReport> findPage(Integer page, Integer size, Long batch_no, String name, String client, Date date) {
//
//        QualityReport qualityReport = new QualityReport();
//        qualityReport.setBatch_no(batch_no);
//        qualityReport.setName(name);
//        qualityReport.setClient(client);
//        qualityReport.setDate(date);
//
//        PageHelper.startPage(page,size);
//        List<QualityReport> list = qualityReportMapper.select(qualityReport);
//        PageInfo<QualityReport> pageInfo = new PageInfo<>(list);
//
//        return pageInfo;
//    }

    public PaginationResult<QualityReport> findPage(Integer page, Integer size, String batch_no, String name, String client, Date date) {

        QueryWrapper<QualityReport> wrapper = new QueryWrapper();
        if (null!=name)
            wrapper.eq("name", name);
        if (null!=client)
            wrapper.eq("client", client);
        if (null!=date)
            wrapper.eq("date", date);
        if (null!=batch_no)
            wrapper.eq("batch_no", batch_no);

        Page<QualityReport> pages = new Page<>(page,size);
        qualityReportMapper.selectPage(pages, wrapper);
        int total = qualityReportMapper.selectCount(wrapper);
        List<QualityReport> list = pages.getRecords();

        PaginationResult<QualityReport> pr = new PaginationResult<>();
        pr.setTotal(total);
        pr.setList(list);
        return pr;
    }
    //动态修改
    public int updateCategoryById(QualityReport qualityReport){
        int result = qualityReportMapper.updateById(qualityReport);
        return result;
    }


}




